package com.dengbw.systemtransfer.service;

import com.dengbw.systemtransfer.global.Column;
import com.dengbw.systemtransfer.mapper.SysRoleMapper;
import com.dengbw.systemtransfer.model.db.SysRole;
import com.dengbw.systemtransfer.model.function.Task;
import lombok.Data;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

/**
 * @author dengbw
 * @date 2021/11/15 3:45 下午
 */
@Service
public class SysRoleService {
    SysRoleMapper sysRoleMapper;

    @Autowired
    public SysRoleService(SysRoleMapper sysRoleMapper) {
        this.sysRoleMapper = sysRoleMapper;
    }


    public void saveRole(String corpId, Long subId) {
        List<SysRole> roles = sysRoleMapper.queryList(v -> v.eq(Column.SUB_ID, subId));
        if (CollectionUtils.isEmpty(roles)) {
            Task.roleTask(corpId, subId).forEach(r -> sysRoleMapper.insert(r));
        }
    }
}
